public class Utilities
{
public static void ResetAllControls(Control form)
{
foreach (Control control in form.Controls)
{
if (control is TextBox)
{
TextBox textBox = (TextBox)control;
textBox.Text = null;
}
if (control is ComboBox)
{
ComboBox comboBox = (ComboBox)control;
if (comboBox.Items.Count > 0)
comboBox.SelectedIndex = 0;
}
if (control is CheckBox)
{
CheckBox checkBox = (CheckBox)control;
checkBox.Checked = false;
}
if (control is ListBox)
{
ListBox listBox = (ListBox)control;
listBox.ClearSelected();
}
}
}
private void button1_Click(object sender, EventArgs e)
{
Utilities.ResetAllControls(this);
}
}
using System;
using System.Collections.Generic;
class Program {
static void Main() {
ConsoleColor foreColor = Console.ForegroundColor;
ConsoleColor backColor = Console.BackgroundColor;
Console.WriteLine("Clearing the screen!");
Console.Clear();
ConsoleColor newForeColor = ConsoleColor.Blue;
ConsoleColor newBackColor = ConsoleColor.Yellow;
}
}